#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


int main()
{
    pid_t id = fork();
    if(id < 0){
        perror("fork");
        exit(27);
    }
    else if(id == 0){
        // child 子进程
        int cnt = 3;
        while(cnt){
            printf("I am child, pid: %d, ppid: %d, cnt: %d\n",getpid(),getppid(),cnt);
            cnt--;
            sleep(1);
        }
    }
    else{
        // father 父进程
        int status = 0;
        int rid = waitpid(id, &status, 0);
        if(rid == id)
        {
            printf("%d\n",WEXITSTATUS(status));
        }
    }

    return 0;
}
